package com.xizi.reflect;

public class ClassloaderAndForNameTest {
    public static void main(String[] args) {
        String Line = "com.xizi.reflect.Line";
        String Point = "com.xizi.reflect.Point";
        System.out.println("下面是测试Classloader的效果");
        testClassloader(Line, Point);
        System.out.println("----------------------------------");
        System.out.println("下面是测试Class.forName的效果");
        testForName(Line, Point);
    }


    private static void testClassloader(String Line, String Point) {
        Class<?> line;
        Class<?> point;
        ClassLoader loader = ClassLoader.getSystemClassLoader();
        try {
            line = loader.loadClass(Line);
            point = loader.loadClass(Point);
            System.out.println("line " + line.getName());
            System.out.println("point " + point.getName());
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    private static void testForName(String Line, String Point) {
        try {
            Class<?> line = Class.forName(Line);
            Class<?> point = Class.forName(Point);
            System.out.println("line   " + line.getName());
            System.out.println("point   " + point.getName());
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
